/*
dateISO('2010-12-10 17:25:10', 'yyyy-MM-dd HH:mm:ss'); //验证通过 

dateISO('2010-12-10 17:25:10', 'yyyy-MM-dd HH:mm'); //验证不通过 

dateISO('2010-12-10', 'yyyy-MM-dd'); //验证通过 

dateISO('2010-12-10 17:25', 'yyyy-MM-dd HH:mm'); //验证通过 

dateISO('17:25:10', 'HH:mm:ss'); //验证通过 
*/
var DateFormatter = {
	Patterns:{
		YEAR      : /y/g,
		MONTH     : /M/g,
		DAY       : /d/g,
		HOUR      : /H/g,
		MINUTE    : /m/g,
		SECOND    : /s/g,
		MILSECOND : /f/g
	},
	FormatPatterns:function(format){
		return eval("/"+
				format
				.replace(this.Patterns.YEAR,'[0-9]')
				.replace(this.Patterns.MONTH,'[0-9]')
				.replace(this.Patterns.DAY,'[0-9]')
				.replace(this.Patterns.HOUR,'[0-9]')
				.replace(this.Patterns.MINUTE,'[0-9]')
				.replace(this.Patterns.SECOND,'[0-9]')
				.replace(this.Patterns.MILSECOND,'[0-9]')+
				"/g");
	},
	DateISO:function(value,format){
		var formatReg = "";
		if(value == "" || format=="")
			return false;
		formatReg = this.FormatPatterns(format);
//		alert(formatReg);
		return formatReg.test(value);
	}
}

//验证手机号
function isTelephone(s) {
    return /^0{0,1}(13[0-9]|15[3-9]|15[0-2]|18[0-9]|17[0-9])[0-9]{8}$/.test(s);
}
//验证是否身份证号
function isIDno(s) {
    return /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[12])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i.test(s);
}
//中文名字
function isChineseName(s) {
    return /^[^\u0000-\u00FF]{2,5}$/.test(s);
}
//qq号
function isQQ(s){
	return /^\d{5,10}$/.test(s);
}
//验证银行卡号
function cardCheck(bankno) {
    if (bankno.length < 16 || bankno.length > 19) {
        //银行卡号长度必须在16到19之间
        return false;
    }
    var num = /^\d*$/;  //全数字
    if (!num.exec(bankno)) {
        //银行卡号必须全为数字
        return false;
    }
    //开头6位
    var strBin = "10,18,30,35,37,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,58,60,62,65,68,69,84,87,88,94,95,98,99";
    if (strBin.indexOf(bankno.substring(0, 2)) == -1) {
        //银行卡号开头6位不符合规范
        return false;
    }
    var lastNum = bankno.substr(bankno.length - 1, 1);//取出最后一位（与luhm进行比较）

    var first15Num = bankno.substr(0, bankno.length - 1);//前15或18位
    var newArr = new Array();
    for (var i = first15Num.length - 1; i > -1; i--) {    //前15或18位倒序存进数组
        newArr.push(first15Num.substr(i, 1));
    }
    var arrJiShu = new Array();  //奇数位*2的积 <9
    var arrJiShu2 = new Array(); //奇数位*2的积 >9

    var arrOuShu = new Array();  //偶数位数组
    for (var j = 0; j < newArr.length; j++) {
        if ((j + 1) % 2 == 1) {//奇数位
            if (parseInt(newArr[j]) * 2 < 9)
                arrJiShu.push(parseInt(newArr[j]) * 2);
            else
                arrJiShu2.push(parseInt(newArr[j]) * 2);
        }
        else //偶数位
            arrOuShu.push(newArr[j]);
    }

    var jishu_child1 = new Array();//奇数位*2 >9 的分割之后的数组个位数
    var jishu_child2 = new Array();//奇数位*2 >9 的分割之后的数组十位数
    for (var h = 0; h < arrJiShu2.length; h++) {
        jishu_child1.push(parseInt(arrJiShu2[h]) % 10);
        jishu_child2.push(parseInt(arrJiShu2[h]) / 10);
    }

    var sumJiShu = 0; //奇数位*2 < 9 的数组之和
    var sumOuShu = 0; //偶数位数组之和
    var sumJiShuChild1 = 0; //奇数位*2 >9 的分割之后的数组个位数之和
    var sumJiShuChild2 = 0; //奇数位*2 >9 的分割之后的数组十位数之和
    var sumTotal = 0;
    for (var m = 0; m < arrJiShu.length; m++) {
        sumJiShu = sumJiShu + parseInt(arrJiShu[m]);
    }

    for (var n = 0; n < arrOuShu.length; n++) {
        sumOuShu = sumOuShu + parseInt(arrOuShu[n]);
    }

    for (var p = 0; p < jishu_child1.length; p++) {
        sumJiShuChild1 = sumJiShuChild1 + parseInt(jishu_child1[p]);
        sumJiShuChild2 = sumJiShuChild2 + parseInt(jishu_child2[p]);
    }
    //计算总和
    sumTotal = parseInt(sumJiShu) + parseInt(sumOuShu) + parseInt(sumJiShuChild1) + parseInt(sumJiShuChild2);

    //计算Luhm值
    var k = parseInt(sumTotal) % 10 == 0 ? 10 : parseInt(sumTotal) % 10;
    var luhm = 10 - k;

    if (lastNum == luhm) {
        return true;
    }
    else {
        return false;
    }
}
